package com.crm.controller;

import com.crm.DTO.RulePoolDto;
import com.crm.common.result.ResultVO;
import com.crm.entity.RulePool;
import com.crm.service.RulePoolService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 配置
 */
@RestController
@Slf4j
@RequestMapping("/rule/pool")
public class RulePoolController {

    @Autowired
    private RulePoolService rulePoolService;

    /**
     * 新增配置
     */
    @PostMapping
    public ResultVO saveRulePool(@RequestBody RulePoolDto rulePoolDto){
        log.info("新增线索池");
        rulePoolService.saveRulePool(rulePoolDto);
        return ResultVO.success();
    }

    /**
     * 回显操作(忽略路径中的ID，总是返回唯一的配置)
     */
    @GetMapping("/{typeId}")
    public ResultVO<RulePool> getRulePoolById(@PathVariable Long typeId){
        log.info("获取规则池配置，忽略传入ID: {}", typeId);
        //忽略路径中的ID，总是返回唯一的配置
        RulePool res = rulePoolService.getRulePoolByTypeId(typeId);
        return ResultVO.success(res);
    }

    /**
     * 更新线索池
     */
    @PutMapping
    public ResultVO updateRulePool(@RequestBody RulePoolDto rulePoolDto){
        log.info("更新线索池");
        rulePoolService.updateByType(rulePoolDto);
        return ResultVO.success();
    }

}
